<template>
	<HyCard title="学历信息">
		<HyForm :hyFormDefault="hyFormDefault" :hyFormConfig="hyFormConfig" :hyFormFields="hyFormFields" ref="hyFormRef" />
	</HyCard>
</template>
<script setup lang="ts">
import HyForm from '/@/components/HyForm/index.vue';
import HyCard from '/@/components/HyCard/index.vue';
import { useDict } from '/@/hooks/dict';

const formType: string = inject('formType', 'submit');

// 定义字典
const { graduation_school, majors_studied, education, academic_degree, is_study } = useDict(
	'graduation_school',
	'majors_studied',
	'education',
	'academic_degree',
	'is_study'
);
//配置基本信息表单
const hyFormFields = computed(() => {
	return {
		graduationSchool: {
			label: '毕业学校',
			type: 'select',
			required: true,
			options: graduation_school.value,
		},
		majorsStudied: {
			label: '所学专业',
			required: true,
			type: 'select',
			options: majors_studied.value,
		},
		education: {
			label: '学历',
			type: 'select',
			options: education.value,
			required: true,
		},
		academicDegree: {
			label: '学位',
			type: 'select',
			options: academic_degree.value,
			required: true,
		},
		isStudy: {
			label: '是否留学',
			type: 'select',
			options: is_study.value,
			change: (val: any) => isStudyChange(val),
		},
		isStudySchool: {
			label: '留学学校名称',
			type: 'input',
			remove: removeIsStudySchool.value,
		},
		diploma: {
			type: 'input',
			hidden: true,
		},
		diplomaFiles: {
			label: '毕业证书',
			required: true,
			type: 'upload',
			fileType: ['.rar', '.zip', '.doc', '.pdf', '.jpg', '.jpeg', '.png'],
			fileSize: 200,
		},
		degreeCertificate: {
			type: 'input',
			hidden: true,
		},
		degreeCertificateFiles: {
			label: '学位证书',
			required: true,
			type: 'upload',
			fileType: ['.rar', '.zip', '.doc', '.pdf', '.jpg', '.jpeg', '.png'],
			fileSize: 200,
		},
	};
});
const hyFormRef = ref();
//动态表单配置
const hyFormConfig = computed(() => {
	return {
		labelWidth: '120px',
		type: formType,
	};
});
const props = defineProps({
	detailData: {
		type: Object,
		default: () => {
			return {};
		},
	},
});
const hyFormDefault = ref({});
watch(
	() => props.detailData,
	(nv1) => {
		hyFormDefault.value = nv1;
		nextTick(() => {
			isStudyChange(nv1.isStudy);
		});
	},
	{ immediate: true }
);
const removeIsStudySchool = ref(true);
const isStudyChange = (vale: string) => {
	if (vale === '1') {
		removeIsStudySchool.value = false;
	} else {
		removeIsStudySchool.value = true;
	}
};
const check = async () => {
	const result = await hyFormRef.value.check();
	if (result) return true;
	return false;
};
const getData = () => {
	return hyFormRef.value.hyForm;
};
defineExpose({ getData, check });
</script>
<style scoped lang="scss"></style>
